import django_filters

from oplatform.models import ChannelData
FREQ = []
all_channel = ChannelData.objects.all()
for channle in all_channel:
    if channle.freq not in FREQ:
        FREQ.append((channle.freq, str(channle.freq)))


class ChannelFilterSet(django_filters.FilterSet):
    freq = django_filters.MultipleChoiceFilter(choices=FREQ, field_name='freq')
    name = django_filters.CharFilter(field_name='name', method='select_by_name')

    def select_by_name(self, queryset, name, value):
        return queryset.filter(name__icontains=value)

    class Meta:
        model = ChannelData
        fields = '__all__'
